package com.pi.tcp.main;

import com.pi.base.util.lang.ByteUtil;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class lockclient {
        public static void main(String[] args) throws IOException {
            //创建Socket对象，连接服务器
            Socket socket=new Socket("118.31.62.203",8899);
            //通过客户端的套接字对象Socket方法，获取字节输出流，将数据写向服务器
//            Socket socket=new Socket("127.0.0.1",8899);
            OutputStream out=socket.getOutputStream();
            //aa 20 00 0c 0a e6 c9 b7 c2 da 38 f3
//            aa 20 00 17 0a e6 c9 b7 c2 da 38 f4 00 03 02 00 01 01 00 02 01 00 03
            byte [] bt = new byte[23];
            bt[0] = (byte)0xAA;
            bt[1] = (byte)0x20;
            bt[2] = (byte)0x00;
            bt[3] = (byte)0x17;


            bt[4] = (byte)0x0A;
            bt[5] = (byte)0xE6;
            bt[6] = (byte)0xC9;
            bt[7] = (byte)0xB7;
            bt[8] = (byte)0xC2;
            bt[9] = (byte)0xDA;
            bt[10] = (byte)0x38;
            bt[11] = (byte)0xF4;
            bt[12] = (byte)0x00;

            bt[13] = (byte)0x03;
            bt[14] = (byte)0x02;
            bt[15] = (byte)0x00;
            bt[16] = (byte)0x01;
            bt[17] = (byte)0x01;
            bt[18] = (byte)0x00;
            bt[19] = (byte)0x02;
            bt[20] = (byte)0x01;
            bt[21] = (byte)0x00;
            bt[22] = (byte)0x03;

            out.write(bt);

            //读取服务器发回的数据，使用socket套接字对象中的字节输入流
            InputStream in=socket.getInputStream();
            byte[] data=new byte[1024];
            int len=in.read(data);
//            System.out.println(new String(data,0,len));
            System.out.println( ByteUtil.byteToHex(data));
            socket.close();
        }

}
